﻿//JumbotCms_4.1 Final
using System;
using System.Data;
using System.Web;
using Jumbot.Common;
using JumbotCms.Common;
namespace JumbotCms.WebFile.Admin
{
    public partial class _mail_ajax : JumbotCms.API.AdminCenter
    {
        private string _operType = string.Empty;
        private string _response = string.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!CheckFormUrl())
            {
                Response.Write("提交有误");
                Response.End();
            }
            Admin_Load("0000", "json");
            this._operType = q("oper");
            switch (this._operType)
            {
                case "sendmail":
                    ajaxSendMail();
                    break;
                default:
                    DefaultResponse();
                    break;
            }
            Response.Write(this._response);
        }

        private void DefaultResponse()
        {
            this._response = JsonResult(0, "未知操作");
        }
        private void ajaxSendMail()
        {
            string _ToMailList = f("txtToMailList");
            string _Title = f("txtTitle");
            string _Body = f("txtBody");
            int _success = 0;
            if (_ToMailList.Length == 0)
            {
                this._response = "top.JumbotCms.Alert('收件人错误', '0');";
                return;
            }
            if (_Title.Length == 0)
            {
                this._response = "top.JumbotCms.Alert('标题错误', '0');";
                return;
            }
            if (_Body.Length == 0)
            {
                this._response = "top.JumbotCms.Alert('内容错误', '0');";
                return;
            }
            string[] _tomail = _ToMailList.Split(',');
            for (int i = 0; i < _tomail.Length; i++)
            {
                if (SendMail(_tomail[i], _Title, _Body))
                    _success++;
            }
            this._response = "top.JumbotCms.Alert('" + _success + "封邮件发送成功', '1');";
        }
    }
}